package com.woniuxy.charin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.charin.mapper.CustomersMapper;
import com.woniuxy.charin.model.entity.Customers;
import com.woniuxy.charin.service.CustomersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @author 28196
* @description 针对表【customers】的数据库操作Service实现
* @createDate 2024-12-23 21:27:49
*/
@Service
public class CustomersServiceImpl extends ServiceImpl<CustomersMapper, Customers>
    implements CustomersService{
    @Autowired
    private CustomersMapper customersMapper;
    @Override
    public Page<Customers> findTopSales(int pageNum, int pageSize, String customerName, String phoneNumber, String accountLevel) {
        Page<Customers> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Customers> wrapper = Wrappers.lambdaQuery(Customers.class);

        // 添加查询条件（如果参数不为空）
        if (StringUtils.hasText(customerName)) {
            wrapper.like(Customers::getCustomerName, customerName);
        }
        if (StringUtils.hasText(phoneNumber)) {
            wrapper.like(Customers::getPhoneNumber, phoneNumber);
        }
        if (StringUtils.hasText(accountLevel)) {
            wrapper.eq(Customers::getAccountLevel, accountLevel);
        }

        // 按积分降序排序
        wrapper.orderByDesc(Customers::getPoints);

        return customersMapper.selectPage(page, wrapper);
    }
}




